<?php
namespace Home\Controller;
use Think\Controller;
class BbqmController extends Controller {
    public function index(){
        indexRvent();//测算首页执行事件
        cookie('orderidnum','Bbqm');
        $this->assign('titleName',titleName('Bbqm',1));//首页名称

        indexRequest($_REQUEST);//测算首页接收数据处理

        $channel=cookie('channel');

        //渠道获取ID
        $channelID=obtain_channelID('QM');
        $this->assign('channelID',$channelID);

        if($_SERVER['HTTP_HOST']=='wx1.bazijingpi.top'){
            cookie('BArecord','粤ICP备14048018号-4');
        }else{
            cookie('BArecord','闽ICP备17022392号');
        }

        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            getToken();
            getTicket();
            $noncestr=noncestr(15);
            $timestamp=time();
            $ticket= S('ticket');
            $wzurl=wxJsdkData();
            $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");

            $this->assign('appid',cookie('APPID'));
            $this->assign('timestamp',$timestamp);
            $this->assign('noncestr',$noncestr);
            $this->assign('signature',$signature);
//            wxShareUrl('CY','Bzcy');//分享地址获取

            if(!empty($_REQUEST['code'])){
                cookie('code',$_REQUEST['code'],7100);
            }
            getCode($wzurl);
            getOopenid();
            cookie('uid',cookie('openid'));
        }

        if(cookie('jploginHC')==''){
            cnzz_pvuv('QM');//执行统计
            cookie('jploginHC',1,30);
        }
        //宝宝起名随机数
        csRandNum('bbqmcs',500000,599999);

        $this->assign('channel',$channel);
        $this->assign('orderidnum','Bbqm');

        if(channelBbqmGs($channel)==2){//过审版本
            $this->display('Bbqm/ZM_bbqm_gs');
        }else if(channelBbqmGs($channel)==3){
            $this->display('Bbqm/ZM_bbqm_gs2');
        } else{
            //$this->display('Bbqm/ZM_bbqm_gs2');
            $this->display('Bbqm/ZM_bbqm');
        }
    }
    public function bbqm_zhifu(){
        $this->assign('titleName',titleName('Bbqm',2,'QM'));//首页名称
        $strData=mb_substr(cookie('orderid'),0,2);
        if($strData!='QM'){cookie('orderid',null);}

        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            $this->assign('wxlogin',cookie('wxlogin'));
            getToken();
            getTicket();
            $noncestr=noncestr(15);
            $timestamp=time();
            $ticket= S('ticket');
            $wzurl=wxJsdkData();
            $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");

            $this->assign('appid',cookie('APPID'));
            $this->assign('timestamp',$timestamp);
            $this->assign('noncestr',$noncestr);
            $this->assign('signature',$signature);

            if(!empty($_REQUEST['code'])){
                cookie('code',$_REQUEST['code'],7100);
            }
            getCode($wzurl);
            getOopenid();
        }

        if($_REQUEST['username']){//返回操作
            cookie('znickname',I('post.username'),604800);
            cookie('zymd',mb_substr($_REQUEST['birthday'],2,10),7200);
            cookie('zhour',mb_substr($_REQUEST['birthday'],13,2),7200);
            cookie('zsex',$_REQUEST['gender'],604800);
            cookie('datetype',mb_substr($_REQUEST['birthday'],0,1));
            $phone=I('request.phone');
            $zt=I("request.zt");
            $ds=I("request.dsz");
            if($ds==1){
                $areaes='单';
            }
        }

        if(!empty($_REQUEST['ordernum'])){//未支付订单
            $arrdata[0]=S('sm_h5test|'.$_REQUEST['ordernum']);
            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);
            cookie('datetype',$arrdata[0]['datetype']);

            cookie('orderid',$_REQUEST['ordernum']);
        }

        $data=cookie('orderid');//获取订单号
        if(empty($data)&&empty($_REQUEST['ordernum'])){
            $orderid='QM'.date('Ymd').mt_rand(100,999).date('His');
            cookie('orderid',$orderid);
        }

        //创建订单
        $hour=cookie('zhour');
        $shop=cookie('orderid');
        $znickname=cookie('znickname');if($znickname=='')$znickname='匿名';
        $zsex=cookie('zsex');if($zsex=='')$zsex=1;
        $channel=cookie('channel');
        $imei=cookie('uid');if(cookie('uid')==''){$imei=cookie('imei');}
        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        $datetype=cookie('datetype');if($datetype=='')$datetype=0;
        defaultPrice();

        channelPay($channel,'QM');//查询渠道价格

        if(cookie('couponPrice')){//是否有使用优惠券
            cookie('price',cookie('couponPrice'));
            $this->assign('discount',10);//优惠券价格
        }else{
            $this->assign('discount',0);//优惠券价格
        }

        if(cookie('discountQczh')){//是否有趣测优惠券
            $price=cookie('price');
            cookie('price',$price/2);
            $remark='discountQczh';
        }


        $datastr=stristr(cookie('znickname'),'测试');
        if($datastr){cookie('price',0.01,604800);}

        csPay($znickname,$channel);//测试价格判断

        $price=cookie('price');
        if(empty($_REQUEST['ordernum'])){
                $arrdata=S('sm_h5test|'.$shop);
                if(empty($arrdata)){
                $smH5testinter=array(
                    'ordernum'=>$shop,
                    'price'=>$price,
                    'username'=>$znickname,
                    'typeid'=>28,
                    'sex'=>$zsex,
                    'createtime'=>date('Y-m-d H:i:m'),
                    'status'=>-1,
                    'datetype'=>$datetype,
                    'year'=>$y,
                    'month'=>$m,
                    'day'=>$d,
                    'hour'=>$hour,
                    'date_remark'=>$remark,
                    'appuserid'=>$imei,
                    'ip'=>cookie('ip'),
                    'channel'=>$channel,
                    'auto_send_sms'=>0,
                    'place'=>0,
                    'phone'=>$phone,
                    'minute'=>$zt,//状态
                    'remark'=>$ds,//单双
                    'areaes'=>$areaes,//单双
                );
                S('sm_h5test|'.$shop,$smH5testinter,2592000);//2592000为30天
                cacheZhiFuOrderid($shop);//支付页缓存订单操作

                $IndexController=A('Index');//Index控制器
                $IndexController->subNumber('QM');//提交订单次数统计
            }else if(!cookie($_REQUEST['username'])){//返回操作
                //更新订单
                $arrdata['username']=$znickname;
                $arrdata['datetype']=$datetype;
                $arrdata['year']=$y;
                $arrdata['month']=$m;
                $arrdata['day']=$d;
                $arrdata['sex']=$zsex;
                S('sm_h5test|'.$shop,$arrdata,2592000);//2592000为30天
            }
        }

        if(cookie('zsex')==1){$zsex='男';}else{$zsex='女';}
        zwmp(cookie('zymd'), cookie('zhour'),$zsex,'zw');
        $sizhu=I('globals.sizhu');
        $this->assign('sizhu',$sizhu);
        $this->assign('sizhuny',I('globals.sizhuny'));//四柱纳音
        $QImING=new \Library\QiMing();
        $wuxingScore=$QImING->wuxingScore($sizhu);
        $this->assign('wuxingScore',$wuxingScore);


        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        $zyinli=yinli($y,$m,$d);
        cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时');//阳历
        cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2]." ".mb_substr($sizhu[3],1,1,'utf-8')."时");//阴历


        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
        }else{
            $xml=wxgzhzf('QM','宝宝起名',cookie('orderid'));//公众号支付回调参数
            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring),true);
            $noncestr=noncestr(15);//随机字符串
            $timestamp=time();//时间戳

            $stringA="appId=".cookie('APPID')."&nonceStr={$noncestr}&package=prepay_id={$val['prepay_id']}&signType=MD5&timeStamp={$timestamp}";
            $stringSignTemp=$stringA."&key=".cookie('wxKEY');
            $sign=strtoupper(md5($stringSignTemp));

            $this->assign('timeStamp',$timestamp);
            $this->assign('nonceStr',$noncestr);
            $this->assign('package','prepay_id='.$val['prepay_id']);
            $this->assign('signType','MD5');
            $this->assign('paySign',$sign);
            $this->assign('appId',cookie('APPID'));
        }

        $this->assign('csNameJump',U('Bbqm/jieguoye','',false).'?ordernum='.cookie('orderid'));//支付成功跳转地址

        $this->assign('channel',cookie('channel'));
        $this->assign('sex',cookie('zsex'));
        $this->assign('date',date('Y/m/d'));

        $this->display('Bbqm/ZM_bbqm_zhifu');
    }
    public function jieguoye(){
        cookie('csType','Bbqm');
        jieguoInterface();//结果页公共函数
        cookie('csTypePrice','158');//一对一价格
        $this->assign('titleName',titleName('Bbqm',3));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            $this->assign('wxlogin',1);
        }

        if(empty($_REQUEST['ordernum'])){
            $zymd= cookie('zymd');
            if(empty($zymd)){//合作随机取值
                cookie('znickname','赵');
                $yRand=rand(2018,2020);
                $mRand=rand(1,12);
                $dRand=rand(1,27);
                $hRand=rand(0,23);
                $zymd=$yRand.'-'.$mRand.'-'.$dRand;
                cookie('zymd',$zymd);
                cookie('zhour',$hRand);
            }
            $zymdArr=explode('-',$zymd);
            $y=$zymdArr[0];//年
            $m=$zymdArr[1]; //月
            $d=$zymdArr[2];//日
            $zyinli=yinli($y,$m,$d);
        }else{
            $ordernum=$_REQUEST['ordernum'];
            $arrdata[0]=jieguoyeArrData($ordernum);

            $areaes=$arrdata[0]['areaes'];

            if($areaes=='单'){
                $wordNum=1;
                cookie('wordNum',$wordNum,60);
            }

            $status=$arrdata[0]['status'];
            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            $zhour=$arrdata[0]['hour'];
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            $zymd= cookie('zymd');
            cookie('orderid',$arrdata[0]['ordernum']);
            cookie('Zorderid',$arrdata[0]['ordernum']);

            $y=mb_substr(cookie('zymd'),0,4);//年
            $m=mb_substr(cookie('zymd'),5,2); //月
            $d=mb_substr(cookie('zymd'),8,2);//日
            $zyinli=yinli($y,$m,$d);
        }

        //一对一亲算下单
//        $QSorder=new \Library\toolOrder();
//        $wxzhifuArr=$QSorder->QSorderXD();
//        if($wxzhifuArr==1){
//            $this->assign('qsPay',1);
//        }else{//更新数据hu
//            if (strpos($user_agent, 'MicroMessenger') == false) {
//                //非微信浏览器访问
//            }else{
//                $this->assign('timeStamp',$wxzhifuArr['timeStamp']);
//                $this->assign('nonceStr',$wxzhifuArr['nonceStr']);
//                $this->assign('package',$wxzhifuArr['package']);
//                $this->assign('signType',$wxzhifuArr['signType']);
//                $this->assign('paySign',$wxzhifuArr['paySign']);
//                $this->assign('appId',$wxzhifuArr['appId']);
//            }
//        }

        if(cookie('zsex')==1){
            $zsex='男';
        }else{
            $zsex='女';
        }
        if($zymd!='') {
            zwmp($zymd, cookie('zhour'), $zsex,'NOdayun');
            $this->assign('lnlylr', I('globals.lnlylr'));
            $shengxiao=I('globals.shengxiao');
            $this->assign('shengxiao',$shengxiao);//生肖
            $sizhu=I('globals.sizhu');
            $this->assign('sizhu',$sizhu);//Z四柱
            $ssarray = array();
            array_push($ssarray, implode(I('globals.nianzhuss')));
            array_push($ssarray, implode(I('globals.yuezhuss')));
            array_push($ssarray, implode(I('globals.shizhuss')));
            $this->assign('nianzhuss', $ssarray);//十神
            $this->assign('canggan', I('globals.canggan'));//藏干

            $this->assign('zhishen', I('globals.zhishen'));//支神
            $this->assign('sizhuny', I('globals.sizhuny'));//四柱纳音
            $this->assign('bzdishi', I('globals.bzdishi'));//八字地势
            $wxsqs=I('globals.wxsqs');
            $this->assign('wxsqs', I('globals.wxsqs'));//旺相休囚死
            $xiys=I('globals.xiys');
            $this->assign('xiys', I('globals.xiys'));//喜用神

            $zhanxing=new \Library\ZhanXing();
            $constellation=$zhanxing->constellation($m,$d);//获取星座


            $qiming=new \Library\QiMing();
            $qimingData=$qiming->qimingData($xiys,$wxsqs,$shengxiao,$constellation,cookie('zsex'));
            $this->assign('qimingData',$qimingData);//起名数据
            $wuxingScore=$qiming->wuxingScore($sizhu);
            $this->assign('wuxingScore',$wuxingScore);//五行得分

            $scWgScore=$qiming->scWgScore($zymd, cookie('zhour'),$qimingData);
            $this->assign('scWgScore',$scWgScore);
        }


        cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时');//阳历
        cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2]." ".mb_substr($sizhu[3],1,1,'utf-8')."时");//阴历
        $nameStlenr=strlen(cookie('znickname'));
        if($nameStlenr>3){$this->assign('strlen',1);
        }else{$this->assign('strlen',0);}

        $this->assign('channel',cookie('channel'));
        $this->assign('znickname',cookie('znickname'));

        $this->assign('wordNum',$wordNum);

        if($_REQUEST['bdTypeNum']==2){//百度合作V2
            $this->display("Bbqm/ZM_baidu_jieguoye_v2");
        }elseif(($_REQUEST['bdTypeNum']==1||cookie('mode')=='pro')&&$status!=1){
            $this->display("Bbqm/ZM_baidu_jieguoye_v1");
        } elseif($_REQUEST['bdTypeNum']==3){//百度合作V3
            $this->display("Bbqm/ZM_baidu_jieguoye_v3");
        }else{
            $this->display('Bbqm/ZM_bbqm_zhifu_jieguoye');
        }
    }

    public function pay(){
        $this->assign('ordername1','宝宝起名');
        $this->assign('ordername2','知命-宝宝起名');
        $this->display("Index/pay");
    }
    public function paywx(){
        H5ZMwxzhifu('QM','宝宝起名',cookie('orderid'),'Bbqm');//知命
    }
    public function updatePhone(){//手机号码修改
        $phone=$_REQUEST['phone'];
        $orderid=cookie('orderid');
        M()->query("update sm_h5test set phone='{$phone}' where ordernum='{$orderid}'");
        echo 1;
    }

    public function dashiList(){//大师一对一列表
        $this->display("Index/dashi_list");
    }
    public function payZhifu(){ //大师一对一亲算下单
        $did=$_REQUEST['did'];
        $dashiArr=array(
            0=>array('name'=>'蔡长安','price'=>588),
            1=>array('name'=>'陈奕哲','price'=>388),
        );
        cookie('price',$dashiArr[$did]['price']);

        $QSorder=new \Library\toolOrder();
        $wxzhifuArr=$QSorder->QSdashiXD();

        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            $this->assign('ordername1','大师一对一亲算');
            $this->assign('ordername2',"知命-大师一对一亲算-{$dashiArr[$did]['name']}");
            $this->display("Index/pay");
        }else{
            $price=cookie('price');
            $orderid=cookie('orderid');
            $csName="知命-大师一对一亲算-{$dashiArr[$did]['name']}";
            $jumpUrl="http://wx1.bazijingpi.top/zhiming/index.php/home-Bzjp-payzfEnd";//成功跳转
            $returnUrl="http://wx1.bazijingpi.top/zhiming/index.php/home-index-mycesuan";//取消跳转

            $notifyUrl='https://hy.yixueqm.com/interface/index.php/Home/Index/notify_url';
            echo "<form id='form' action='http://wx1.bazijingpi.top/zhiming/index.php/Home-Interface-interfaceWechatPay' method='POST'>
               <input type='hidden'  name='orderid' value=\"{$orderid}\">
               <input type='hidden'  name='price' value=\"{$price}\">
               <input type='hidden'  name='csName' value=\"{$csName}\">
               <input type='hidden'  name='jumpUrl' value=\"{$jumpUrl}\">
               <input type='hidden'  name='returnUrl' value=\"{$returnUrl}\">
               <input type='hidden'  name='notifyUrl' value=\"{$notifyUrl}\">
               <input type='hidden'  name='getTokenType' value='kaiyun'>
            </form>
            <script type='text/javascript'>document.getElementById('form').submit()</script>"
            ;
        }
    }


    //百度合作
    public function bdIndex(){//首页
        if($_REQUEST['uid']){
            cookie('uid',$_REQUEST['uid']);
        }else{
            $uid=cookie('uid');
            if(empty($uid)){$uid=date('Ymd').mt_rand(10000,99999).date('His');cookie('uid',$uid);}
        }

        cookie('orderidHzBd',null);
        S('QMHZ202001073058153330'.'status',1,120);
        cookie('timeStrto',time()+7200);//倒计时时间戳


        if($_REQUEST['mode']){
            $mode=$_REQUEST['mode'];
            cookie('mode',$mode);
        }
        if($mode=='pro'){
            cookie('price',69);
        }else{
            cookie('price',39);
        }

        $this->assign('priceYj',cookie('price')*5);
        $this->assign('orderid',$_REQUEST['orderid']);
        $this->display("Bbqm/ZM_baidu_index");
    }
    public function bdJieguoV1(){//结果2   范例样式
        if($_REQUEST['orderid']){
            cookie('orderid',$_REQUEST['orderid']);
        }

        $orderid=cookie('orderid');

        if(cookie('zymdCookieTime'.$orderid)==''){
            $yRand=rand(2018,2020);
            $mRand=rand(1,12);
            $dRand=rand(1,27);
            $hRand=rand(0,23);
            $zymd=$yRand.'-'.$mRand.'-'.$dRand;
            cookie('zymdCookieTime'.$orderid,1,600);
            cookie('zymd',$zymd);
            cookie('zhour',$hRand);
        }
        cookie('znickname','赵');

        if(cookie('mode')=='pro'){
            redirect(U('Bbqm/jieguoye','',false)."?bdTypeNum=1");
        }else{
            redirect(U('Bbqm/bdJieguoV3','',false));
            //$this->display("Bbqm/ZM_baidu_jieguoye_v1");
        }
    }
    public function bdJieguoV2(){//结果2  完善资料版
        if($_REQUEST['orderid']){
            cookie('orderid',$_REQUEST['orderid']);
        }
        if($_REQUEST['birthday']){
            $birthday=$_REQUEST['birthday'];
            $username=$_REQUEST['username'];
            $sex=$_REQUEST['gender'];
            $zymdArr=explode('-',$birthday);
            $zymd=$zymdArr[1].'-'.$zymdArr[2].'-'.$zymdArr[3];

            cookie('zymd',$zymd);
            cookie('znickname',$username);
            cookie('zsex',$sex);
            cookie('zhour',$zymdArr[4]);
        }
        redirect(U('Bbqm/jieguoye','',false)."?bdTypeNum=2");
        $this->display("Bbqm/ZM_baidu_jieguoye_v2");
    }
    public function bdJieguoV3(){//结果3  简化版
        $orderid=cookie('orderid');
        if(cookie('zymdCookieTime'.$orderid)==''){
            $yRand=rand(1980,2020);
            $mRand=rand(1,12);
            $dRand=rand(1,27);
            $hRand=rand(0,23);
            $zymd=$yRand.'-'.$mRand.'-'.$dRand;
            cookie('zymdCookieTime'.$orderid,1,600);
            cookie('zymd',$zymd);
            cookie('zhour',$hRand);
        }

        cookie('zsex',0);
        redirect(U('Bbqm/jieguoye','',false)."?bdTypeNum=3");
        $this->display("Bbqm/ZM_baidu_jieguoye_v3");
    }
    public function bdOrderInsert(){
        $orderid=cookie('orderidHzBd');//获取订单号
        if(empty($orderid)){
            $orderid='QMHZ'.date('Ymd').mt_rand(1000,9999).date('His');
            $price=cookie('price');
            $uid=cookie('uid');
            cookie('orderid',$orderid,290);
            cookie('orderidHzBd',$orderid,290);
            M()->query("insert into sm_h5test_baidu (orderid,price,uid)values('{$orderid}','{$price}','{$uid}')");
        }
    }
    public function bdpayZfb(){
        $this->bdOrderInsert();

        $this->assign('ordername1','宝宝起名');
        $this->assign('ordername2','知命-宝宝起名');
        $this->display("Index/pay");
    }
    public function bdpayWx(){
        $this->bdOrderInsert();
        $orderid=cookie('orderidHzBd');//获取订单号

        $jumpUrl=cookie($orderid.'jumpUrl');
        if($jumpUrl){header("location:".$jumpUrl);exit;}

        $price=cookie('price');
        $price*=100;

        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {$ip = getenv('HTTP_CLIENT_IP');
        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {$ip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {$ip = getenv('REMOTE_ADDR');
        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {$ip = $_SERVER['REMOTE_ADDR'];
        }
        $ip=preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';

        $scene_info="{\"h5_info\": {\"type\":\"Wap\",\"wap_url\": \"https://hy.yixueqm.com\",\"wap_name\": \"知命支付\"}}";
        $noncestr=noncestr(15);
        $KEY=C('KEY');
        $MCHID=C('H5GMCHID');
        $APPID=C('H5APPID');

        $body='宝宝起名';
        $type='MWEB';
        $notifyUrl="https://{$_SERVER['HTTP_HOST']}/zhiming/index.php/Home-Index-notify_urlwx";
        $stringA="appid=".$APPID."&body={$body}&mch_id={$MCHID}&nonce_str={$noncestr}&notify_url={$notifyUrl}&out_trade_no={$orderid}&scene_info={$scene_info}&spbill_create_ip={$ip}&total_fee={$price}&trade_type={$type}";
        $stringSignTemp=$stringA."&key=".$KEY; //注：key为商户平台设置的密钥key
        $sign=strtoupper(md5($stringSignTemp));

        $strData=array(
            'appid'=>$APPID,
            'mch_id'=>$MCHID,
            'nonce_str'=>$noncestr,
            'sign'=>$sign,
            'body'=>$body,
            'out_trade_no'=>$orderid,
            'total_fee'=>$price,
            'spbill_create_ip'=>$ip,
            'notify_url'=>$notifyUrl,
            'trade_type'=>$type,
            'scene_info'=>$scene_info,
        );


        $xml = "<xml>";
        foreach ($strData as $key=>$val)//数组转xml
        {
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        $strData=$xml;
        //$json=json_encode($data,JSON_UNESCAPED_UNICODE);
        $headers=array(
            'Content-Type:text/xml;charset=utf-8',
        );
        $url="https://api.mch.weixin.qq.com/pay/unifiedorder";

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
        curl_setopt($ch,CURLOPT_URL,$url); //设置请求地址
        curl_setopt($ch,CURLOPT_POST,true); //post请求
        curl_setopt($ch,CURLOPT_POSTFIELDS,$strData);// post请求的数据
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//不需要证书验证
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//不直接输出到页面
        $json = curl_exec($ch);
        $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);

        $xmlstring = simplexml_load_string($json, 'SimpleXMLElement', LIBXML_NOCDATA);
        $val = json_decode(json_encode($xmlstring),true);
        curl_close($ch);
        $redirect_url='https://'.$_SERVER['HTTP_HOST']."/zhiming/index.php/Home-Index-return_urlwx?orderid={$orderid}";
        $redirect_url=urlencode($redirect_url);

        if(empty($val['mweb_url'])){
            if(mb_substr($val['err_code_des'],0,3)==201){
                $wzurl=wxJsdkData();
                echo $val['err_code_des'];
                redirect($wzurl);
            }
            dump($val);echo 'H5ZMwxzhifu';exit;
        }
        $jumpUrl=$val['mweb_url']."&redirect_url=".$redirect_url;
        if($val['mweb_url']){
            cookie($orderid.'jumpUrl',$jumpUrl,250);
        }
        header("location:".$val['mweb_url']."&redirect_url=".$redirect_url);
    }

    public function bdSelectLoop(){//循环查询订单
        $orderid=$_REQUEST['orderid'];
        $statusNum=S($orderid.'status');
        echo $statusNum;
    }
    public function dbUpdatePhone(){//百度合作绑定
        $phone=$_REQUEST['phone'];
        $orderid=cookie('orderid');
        M()->query("update sm_h5test_baidu set phone='{$phone}' where ordernum='{$orderid}'");
        echo 1;
    }
    public function orderAreaes(){//订单单字显示
        $ordernum=$_REQUEST['ordernum'];
       if($ordernum=='QM20200203711161156'){
           $selectArr=jieguoyeArrData($ordernum);
           $selectArr["areaes"]='单';
           $saveTime=C('saveTime');//保存时间
           M()->query("update sm_h5test set areaes='单' where ordernum='{$ordernum}'");
           S('sm_h5test|'.$ordernum,$selectArr,$saveTime);
       }
    }
    public function updateChannelUrl(){//渠道版本切换
        $channel=$_REQUEST['channel'];
        $type=$_REQUEST['type'];//1.最新版本  2.过审1  3.过审2
        if(empty($type))$type=1;
        S('updateChannelUrl'.$channel,$type,2592000);
        $nameArr=array(
            1=>'最新版本',
            2=>'过审版本',
            3=>'过审版本2',
        );
        echo $channel.":".$nameArr[$type];
    }
}